<!DOCTYPE html>
<html lang="en"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <base th:href="@{/}">
    <title>诊记录列表</title>
    <link rel="stylesheet" href="/css/bootstrap.min.css" />
    <link rel="stylesheet" href="/css/style1.css" />
    <link rel="stylesheet" href="/css/style.css" />
    <script src="/js/jquery.min.js"></script>
    <SCRIPT src="/js/bootstrap.bundle.min.js"></SCRIPT>
    <style>
        .btn2{
            color: #eec4a0;
            background: #fdf6ec;
            border: 1px solid #f8e6cb;
        }
        .btn2:hover,.btn2:focus{
            color: #fff !important;
            background-color: #eec4a0 !important;
            border-color: #eec4a0 !important;
        }
        .view{
            color: #eec4a0;
        }
        .view:hover,.view:focus{
            color: #fff !important;
        }
    </style>
</head>
<body>
<div th:insert="~{user/header}"></div>
<main id="main">
    <!--副标题-->
    <section class="breadcrumbs">
        <div class="container">
            <div class="d-flex justify-content-between align-items-center">
                <h2 id="pageTitle">就诊记录</h2>
                <ol>
                    <li><a href="index.html">首页</a></li>
                    <li id="breadcrumbItem"><a href="#" ></a>就诊记录</li>
                </ol>
            </div>
        </div>
    </section>
    <section class="inner-page">
        <div class="container">
            <div class="card">
                <div class="card-header">
                    <h3 class="card-title">就诊记录列表</h3>
                </div>
                <div class="card-body">

                    <div class="table-responsive">
                        <table class="table text-center">
                            <tbody class="text-center">
                            <tr>
                                <th>编号</th>
                                <th>患者姓名</th>
                                <th>患者身份证</th>
                                <th>医生</th>
                                <th>就诊日期</th>
                                <th>医嘱病例</th>
                            </tr>
                            <tr th:each="record : ${records}">
                                <td th:text="${record.id}"></td>
                                <td th:text="${record.name}"></td>
                                <td th:text="${record.cno}"></td>
                                <td th:text="${record.dname}"></td>
                                <td th:text="${record.zdrq}"></td>
                                <td>
                                    <a th:href="@{/doctor/showADetail(id=${record.id})}"
                                       class="btn btn-sm show-modal-link" style="color: #0accce;background: #e5fcfb;border-color: #ace2dd;">查看医嘱病例</a>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="6" style="border: none;">
                                    <ul class="pagination justify-content-center">
                                        <li class="page-item" th:if="${currentPage} != 1">
                                            <a class="page-link"
                                               th:href="@{/user/showURecordList(currentPage=${currentPage - 1})}">上一页</a>
                                        </li>
                                        <li class="page-item disabled">
                                            <a class="page-link" href="#">第<span
                                                    th:text="${currentPage}"></span>页</a>
                                        </li>
                                        <li class="page-item disabled">
                                            <a class="page-link" href="#">共<span
                                                    th:text="${totalPage}"></span>页</a>
                                        </li>
                                        <li class="page-item" th:if="${currentPage} !=${totalPage}">
                                            <a class="page-link"
                                               th:href="@{/user/showURecordList(currentPage=${currentPage + 1})}">下一页</a>
                                        </li>
                                    </ul>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </section>
</main>
<!-- 模态框结构 -->
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content">
            <div class="modal-header">
                <h2 class="modal-title" id="exampleModalLabel">医嘱病例详情</h2>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body">
                <div class="row col-12">
                    <div id="medicalOrderDetail">
                        <!-- 医嘱详情加载中... -->
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    document.addEventListener('DOMContentLoaded', function () {
        var modalElement = document.getElementById('exampleModal');
        var modal = new bootstrap.Modal(modalElement);

        // 选择所有具有 'show-modal-link' 类的按钮
        var showModalLinks = document.querySelectorAll('.show-modal-link');

        // 为每个按钮添加事件监听器
        showModalLinks.forEach(function(link) {
            link.addEventListener('click', function(event) {
                event.preventDefault();
                fetch(this.href)
                    .then(response => response.text())
                    .then(html => {
                        document.getElementById('medicalOrderDetail').innerHTML = html;
                        modal.show();
                    })
                    .catch(error => console.error('加载失败:', error));
            });
        });

        // 模态框隐藏后的清理操作
        modalElement.addEventListener('hidden.bs.modal', function () {
            modalElement.setAttribute('aria-hidden', 'true');
            document.getElementById('Detail').innerHTML = '';
        });
    });
</script>
</body>
</html>